//package allrobots.WebSocket;
//
//import allrobots.DispensingMachine.DMFinishToSystem;
//import org.springframework.web.socket.TextMessage;
//import org.springframework.web.socket.WebSocketSession;
//import org.springframework.web.socket.handler.TextWebSocketHandler;
//
//import java.util.concurrent.ExecutorService;
//import java.util.concurrent.Executors;
//
//public class WebSocketHandlerImpl extends TextWebSocketHandler {
//
//    // 创建一个线程池来处理消息
//    private final ExecutorService executorService = Executors.newSingleThreadExecutor();
//
//    @Override
//    public void afterConnectionEstablished(WebSocketSession session) throws Exception {
//        System.out.println("新连接建立：" + session.getId());
//        // 创建一个单独的线程来持续监听并处理消息
//    }
//
//    @Override
//    public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
//        System.out.println("收到前端消息: " + message.getPayload());
//        // 处理完消息后可以返回响应
//        String responseMessage = "已收到消息: " + message.getPayload();
//        session.sendMessage(new TextMessage(responseMessage));  // 发送回应给前端
//        //调用发药机功能线程向系统发送请求
//        new Thread(new DMFinishToSystem()).start();
//    }
//
//    @Override
//    public void afterConnectionClosed(WebSocketSession session, org.springframework.web.socket.CloseStatus status) throws Exception {
//        super.afterConnectionClosed(session, status);
//        System.out.println("连接关闭：" + session.getId());
//    }
//
//    @Override
//    public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
//        super.handleTransportError(session, exception);
//        System.out.println("WebSocket连接异常：" + exception.getMessage());
//    }
//}